#!/usr/bin/python3
#-*- coding: utf-8 -*-
# @Time    : 2018/10/16 下午7:52
# @Author  : way
# @Email   : wuaoyi@gmail.com
# @File    : email.py
# @Software: PyCharm
import requests,json
import time
import sendemail
import judge

static_url = 'http://www.szse.cn/disclosure/listed/bulletinDetail/index.html?'

arr = []
with open("test.txt",'r+',encoding="utf-8") as fw:
    for i in fw.readlines():
        arr.append(i.strip())

url3 = 'http://www.szse.cn/api/disc/announcement/annList?random=0.14432946372417632?'

news = []
new_content = []

while True:
    #判断是不是工作日
    if judge.workDay() == 1:

            for i in arr:

                payload2 = {'seDate': [time.strftime('%Y-%m-%d',time.localtime(time.time())), time.strftime('%Y-%m-%d',time.localtime(time.time()))], 'stock': [i], 'channelCode': ["listedNotice_disc"], 'pageSize': 30, 'pageNum': 1}

                print(payload2)

                data = requests.post(url3,data=json.dumps(payload2),headers={'Content-Type': 'application/json'})

                data.encoding = 'utf-8'

                p_json = data.json()



                for i in p_json['data']:
                    if i not in news:
                        news.append(i['title'])
                        strlist = i['attachPath'].split('/')
                        #new_url = static_url+strlist[len(strlist)-1].replace('.PDF','')
                        new_url = static_url+i['id']
                        new_content.append(i['title']+','+new_url)


            for i in new_content:
                strlist = i.split(',')
                print(strlist)
                sendemail.sendemail(strlist[0],strlist[1])
            print("发送完毕")
            new_content = []
            time.sleep(900)

    else:
        print("非工作日或者非工作日时间段")
        continue

